module MC.UI {
    export class UpPic {
        public constructor() {
            this.PicFileDiv();
            this.PhotoClip();//
            this.loadData();
        }

        private pic = new MC.View.PhotoClip();

        /**
         * 直接上传图片的方式
         * */
        private PicFileDiv() {
            let bFileDivList = $('PicFileDiv');
            for (let i = 0; i < bFileDivList.length; i++) {
                let obj = $(bFileDivList[i]);
                let pcid = obj.attr('id');
                if (obj.attr('TXupfileDiv') == 'true') {
                    continue;
                }
                let bixu = ``;
                if (obj.attr('bixu') == 'true') {
                    bixu = `<span class="red">*</span>`;
                }
                let title = obj.attr('title');///<input type="hidden" id="sfzzm" value="" class="sfzFileVal">
                let html = `
				<div class="pic">
						
						<img class="img" />
					</div>
            <p class="spantitle">` + bixu + `` + title + `</p>
		`;
                obj.html(html);
            }

            $('.H5body').on('click', 'PicFileDiv .pic', function () {
                let obj = $(this);
                let pcid = obj.parent().attr('id');
                if (obj.parent().attr('TXupfileDiv') == 'true') {
                    return;
                }
                MC.API.UpPic((url: string) => {
                    ///console.log(pcid,url);
                    obj.find('.img').attr('src', url);
                    $('[id=' + pcid + ']').val(url);
                });
            });
        }

        /** 给图片赋值 */
        private loadData() {
            let bFileDivList = $('PicFileDiv');
            for (let i = 0; i < bFileDivList.length; i++) {
                let obj = $(bFileDivList[i]);
                let val = obj.val();
                obj.find('.img').attr('src', val);
            }
        }

        /**
         * 剪辑图片上传方式
         * */
        private PhotoClip() {
            let bFileDivList = $('PhotoClip');
            for (let i = 0; i < bFileDivList.length; i++) {
                let obj = $(bFileDivList[i]);
                let bixu = ``;
                if (obj.attr('bixu') == 'true') {
                    bixu = `<span class="red">*</span>`;
                }
                let title = obj.attr('title');///<input type="hidden" id="sfzzm" value="" class="sfzFileVal">
                let html = `
				<div class="pic">
						
						<img class="img" />
					</div>
            <p class="spantitle">` + bixu + `` + title + `</p>
		`;
                obj.html(html);
            }
            let mthis=this;
            $('.H5body').on('click', 'PhotoClip .pic', function () {
                let obj = $(this);
                let pcid = obj.parent().attr('id');
                mthis.pic.selPic((url: any) => {
                    // this.setPic('imgMain', url.img);
                    obj.find('.img').attr('src', url.img);
                    obj.parent().val(url.img);
                   // $('[id=' + pcid + ']').val(url.img);
                });
            });
        }
    }
}